package com.woniuxy.oa.dao.provider;

import com.woniuxy.oa.entity.query.EmployeeQuery;
import org.apache.ibatis.jdbc.SQL;

/**
 * @Auther: 毓
 * @Date: 2019/12/26 14:27
 * @Description:
 */
public class EmployeeProvider {
    public String select(EmployeeQuery user) {
        return new SQL() {
            {
                SELECT("e.*,d.deptname deptName,d.id");
                FROM("oa_emp e ");
                LEFT_OUTER_JOIN("oa_dept d on e.deptid=d.id");
                if (user.getEmpNo() != null && user.getEmpNo().trim().length() != 0) {
                    WHERE("e.empno=#{empNo}");
                }
                if (user.getName() != null && user.getName().trim().length() != 0) {
                    WHERE("e.name like  concat(\"%\",#{name},\"%\")");
                }
                if ("m".equals(user.getGenderQuery())) {
                    WHERE("gender='m'");
                }
                if ("f".equals(user.getGenderQuery())) {
                    WHERE("gender='f'");
                }
                if (user.getSmallHiredate() != null && user.getSmallHiredate().trim().length() != 0) {
                    WHERE("entryTime>=#{smallHiredate}");
                }
                if (user.getBigHiredate() != null && user.getBigHiredate().trim().length() != 0) {
                    WHERE("entryTime<=#{bigHiredate}");
                }
                if (user.getStatusQuery() != null && "1".equals(user.getStatusQuery())) {
                    WHERE("status='1'");
                }
                if (user.getStatusQuery() != null && "2".equals(user.getStatusQuery())) {
                    WHERE("status='2'");
                }
                if (user.getPhoneNum() != null && user.getPhoneNum().trim().length() != 0) {
                    WHERE("phonenum=#{phoneNmu}");
                }
                if (user.getSmallBirthDate() != null) {
                    WHERE("e.birthdate>=#{smallBirthDate}");
                }
                if (user.getBigBirthDate() != null) {
                    WHERE("e.birthdate<=#{bigBirthDate}");
                }
                if (user.getDept().getId() != null) {
                    WHERE("e.deptid=#{dept.id}");
                }
            }
        }.toString();
    }
}